home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / FLTK-1.0.6 / src / Fl_Light_Button.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  2.3 KB  |  75 lines

  1. //
  2. // "$Id: Fl_Light_Button.cxx,v 1.4 1999/01/07 19:17:21 mike Exp $"
  3. //
  4. // Lighted button widget for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-1999 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems to "fltk-bugs@easysw.com".
  24. //
  25.  
  26. // Subclass of Fl_Button where the "box" indicates whether it is
  27. // pushed or not, and the "down box" is drawn small and square on
  28. // the left to indicate the current state.
  29.  
  30. // The default down_box of zero draws a rectangle designed to look
  31. // just like Flame's buttons.
  32.  
  33. #include <FL/Fl.H>
  34. #include <FL/Fl_Light_Button.H>
  35. #include <FL/fl_draw.H>
  36.  
  37. void Fl_Light_Button::draw() {
  38.   if (box()) draw_box(this==Fl::pushed() ? down(box()) : box(), color());
  39.   Fl_Color col = value() ? selection_color() : color();
  40.   int d = h()/6;
  41.   int W = w()<h() ? w() : h();
  42.   if (down_box()) {
  43.     // draw other down_box() styles:
  44.     draw_box(down_box(), x()+d, y()+d+1, W-2*d-2, W-2*d-2, col);
  45.   } else {
  46.     // if down_box() is zero, draw light button style:
  47.     int hh = h()-2*d;
  48.     int ww = hh/2+1;
  49.     int xx = d*2;
  50.     if (w()<ww+2*xx) xx = (w()-ww)/2;
  51.     draw_box(FL_THIN_DOWN_BOX, x()+xx, y()+d, ww, hh, col);
  52.   }
  53.   draw_label(x()+W-d, y(), w()-W+d, h());
  54. }
  55.  
  56. int Fl_Light_Button::handle(int event) {
  57.   switch (event) {
  58.   case FL_RELEASE:
  59.     if (box()) redraw();
  60.   default:
  61.     return Fl_Button::handle(event);
  62.   }
  63. }
  64.  
  65. Fl_Light_Button::Fl_Light_Button(int x, int y, int w, int h, const char* l)
  66. : Fl_Button(x, y, w, h, l) {
  67.   type(FL_TOGGLE_BUTTON);
  68.   selection_color(FL_YELLOW);
  69.   align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE);
  70. }
  71.  
  72. //
  73. // End of "$Id: Fl_Light_Button.cxx,v 1.4 1999/01/07 19:17:21 mike Exp $".
  74. //
  75.